#ifndef  __Master__
#define   __Master__
#include <string.h>
#include "Subject.h"
#include "List.h"

typedef struct {
	Subject super;
	char name[100];
}Master;



void __masterAddObserver(Subject* self, Observer* observer) {
	List* observers = &(self->observers);
	listAdd(observers, (Object*)observer);
}

void __masterNotifyObservers(Subject* self) {
	List* observers = &(self->observers);
	for (auto& i = observers->next; i != 0; i = i->next) {
		Observer* observer = ((Observer*)(i->val));
		observer->update(observer, ((Master*)self)->name);
	}
}

void MasterConstrct(Master* self, const char* name) {
	SubjectConstruct((Subject*)self);
	((Subject*)self)->subjectAddObserver = __masterAddObserver;
	((Subject*)self)->subjectNotifyObservers = __masterNotifyObservers;
	strcpy(self->name, name);
}

void MasterDestruct(Master* self) {
	SubjectDestruct((Subject*)self);
}

void MasterCall(Master* self) {
	Subject* subject = ((Subject*)self);
	subject->subjectNotifyObservers(subject);
}

#endif